﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OOAD_Project_Editor.Foundation;
using OOAD_Project_Engine.Foundation.MyEventArgs;
using OOAD_Project_Engine.Foundation.Interfaces;

namespace OOAD_Project_Editor.Presentation
{
    public partial class AsignEntityNameForm : Form
    {
        public event EventHandler<EntityEventArgs> OnNameSubmited;
        IEntity entity;
        public AsignEntityNameForm(IEntity entity)
        {
            this.entity = entity;
            InitializeComponent();
            KeyDown += onKeyDown;
        }

        void onKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
                submit();
        }

        private void submitButton_Click(object sender, EventArgs e)
        {
            if (nameTextBox.Text == "")
            {
                MessageBox.Show("Name can't be NULL");
            }
            else
            {
                submit();
            }
        }

        private void submit()
        {
            EntityEventArgs e = new EntityEventArgs(entity);
            e.Name = nameTextBox.Text;
            if (OnNameSubmited != null)
                OnNameSubmited(this, e);
            this.Close();
        }
    }
}
